import {
  puBillVouchInvoiceRecords,
  puBillVouchInvoice,
  puBillVouchDeleteInvoice,
  puBillVouchVerifyInvoice,
  puBillVouchExecMatch,
  puBillVouchTempSave,
  puBillVouchSubmit,
} from '/@/api/srm/cw/billvouch/puBillVouch';

import {
  puVmiBillVouchInvoiceRecords,
  puBillVouchInvoice as puVmiUploadInvoice,
  puVmiBillVouchDeleteInvoice,
  puVmiBillVouchVerifyInvoice,
  puVmiBillVouchExecMatch,
  puVmiBillVouchTempSave,
  puVmiBillVouchSubmit,
} from '/@/api/srm/cw/billvouch/puVmiBillVouch';

export type InvoiceApi = {
  invoiceRecords: (params: any) => Promise<any>;
  uploadInvoice: (
    params: any,
    onUploadProgress: (e: any) => void,
    cancelToken?: any,
  ) => Promise<any>;
  deleteInvoice: (params: any) => Promise<any>;
  verifyInvoice: (params: any) => Promise<any>;
  execMatch: (params: any) => Promise<any>;
  tempSave: (params: any) => Promise<any>;
  submit: (params: any) => Promise<any>;
};

export function createInvoiceApi(mode: 'normal' | 'vmi'): InvoiceApi {
  if (mode === 'vmi') {
    return {
      invoiceRecords: puVmiBillVouchInvoiceRecords,
      uploadInvoice: (params, onUploadProgress, cancelToken?) =>
        puVmiUploadInvoice(params, onUploadProgress, cancelToken),
      deleteInvoice: puVmiBillVouchDeleteInvoice,
      verifyInvoice: puVmiBillVouchVerifyInvoice,
      execMatch: puVmiBillVouchExecMatch,
      tempSave: puVmiBillVouchTempSave,
      submit: puVmiBillVouchSubmit,
    };
  }
  return {
    invoiceRecords: puBillVouchInvoiceRecords,
    uploadInvoice: (params, onUploadProgress, cancelToken?) =>
      puBillVouchInvoice(params, onUploadProgress, cancelToken),
    deleteInvoice: puBillVouchDeleteInvoice,
    verifyInvoice: puBillVouchVerifyInvoice,
    execMatch: puBillVouchExecMatch,
    tempSave: puBillVouchTempSave,
    submit: puBillVouchSubmit,
  };
}